#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>

void pause();

int main(int argc, char *argv[])
{
SDL_Surface *ecran = NULL, *imageDeFond = NULL, *play = NULL, *replay = NULL, *instruction = NULL, *option = NULL, *exit = NULL, *ll = NULL;
SDL_Rect positionFond, positionplay, positionreplay, positioninstruction, positionoption, positionexit, positionll;
int continuer = 1, b=0
;
positionFond.x = 0;
positionFond.y = 0;
positionll.x = 0;
positionll.y = 0;
positionplay.x = 250;
positionplay.y = 0;
positionreplay.x = 250;
positionreplay.y = 10;
positioninstruction.x = 250;
positioninstruction.y = 20;
positionoption.x = 250;
positionoption.y = 30;
positionexit.x = 250;
positionexit.y = 40;
SDL_Init(SDL_INIT_VIDEO);
  
 ecran = SDL_SetVideoMode(800,600, 32, SDL_HWSURFACE |SDL_DOUBLEBUF); 
 SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255)); 

SDL_WM_SetCaption("menu", NULL);

/* Chargement d'une image Bitmap dans une surface */
imageDeFond = SDL_LoadBMP("background.bmp");
SDL_BlitSurface(imageDeFond, NULL, ecran, &positionFond);

ll= SDL_LoadBMP("congratulation.bmp");
//test=SDL_LoadBMP("congratulation.bmp");


play = SDL_LoadBMP("1.bmp");
SDL_SetColorKey(play, SDL_SRCCOLORKEY, SDL_MapRGB(play->format, 255, 255, 255));
SDL_BlitSurface(play, NULL, ecran, &positionplay);

replay = SDL_LoadBMP("2.bmp");
SDL_SetColorKey(replay, SDL_SRCCOLORKEY, SDL_MapRGB(replay->format, 255, 255, 255));
SDL_BlitSurface(replay, NULL, ecran, &positionreplay);

instruction = SDL_LoadBMP("3.bmp");
SDL_SetColorKey(instruction, SDL_SRCCOLORKEY, SDL_MapRGB(instruction->format, 255, 255, 255));
SDL_BlitSurface(instruction, NULL, ecran, &positioninstruction);

option = SDL_LoadBMP("4.bmp");
SDL_SetColorKey(option, SDL_SRCCOLORKEY, SDL_MapRGB(option->format, 255, 255, 255));
SDL_BlitSurface(option, NULL, ecran, &positionoption);

exit = SDL_LoadBMP("5.bmp");
SDL_SetColorKey(exit, SDL_SRCCOLORKEY, SDL_MapRGB(exit->format, 255, 255, 255));
SDL_BlitSurface(exit, NULL, ecran, &positionexit);
SDL_Flip(ecran);

SDL_Event event; 


while (continuer)
{
    SDL_WaitEvent(&event);
    switch(event.type)
    {
        case SDL_QUIT:
            continuer = 0;
            break;

 case SDL_MOUSEMOTION: 

if((event.motion.y>110 && event.motion.y<160) && (event.motion.x>540 && event.motion.x <770)) 
{

play = SDL_LoadBMP("1a.bmp");
SDL_SetColorKey(play, SDL_SRCCOLORKEY, SDL_MapRGB(play->format, 255, 255, 255));
SDL_BlitSurface(play, NULL, ecran, &positionplay);

replay = SDL_LoadBMP("2.bmp");
SDL_SetColorKey(replay, SDL_SRCCOLORKEY, SDL_MapRGB(replay->format, 255, 255, 255));
SDL_BlitSurface(replay, NULL, ecran, &positionreplay);

instruction = SDL_LoadBMP("3.bmp");
SDL_SetColorKey(instruction, SDL_SRCCOLORKEY, SDL_MapRGB(instruction->format, 255, 255, 255));
SDL_BlitSurface(instruction, NULL, ecran, &positioninstruction);

option = SDL_LoadBMP("4.bmp");
SDL_SetColorKey(option, SDL_SRCCOLORKEY, SDL_MapRGB(instruction->format, 255, 255, 255));
SDL_BlitSurface(option, NULL, ecran, &positionoption);

exit = SDL_LoadBMP("5.bmp");
SDL_SetColorKey(exit, SDL_SRCCOLORKEY, SDL_MapRGB(exit->format, 255, 255, 255));
SDL_BlitSurface(exit, NULL, ecran, &positionexit);

SDL_Flip(ecran);
break;
}


else if((event.motion.y>180 && event.motion.y<230) && (event.motion.x>540 && event.motion.x <770)) 
{
play = SDL_LoadBMP("1.bmp");
SDL_SetColorKey(play, SDL_SRCCOLORKEY, SDL_MapRGB(play->format, 255, 255, 255));
SDL_BlitSurface(play, NULL, ecran, &positionplay);

replay = SDL_LoadBMP("2a.bmp");
SDL_SetColorKey(replay, SDL_SRCCOLORKEY, SDL_MapRGB(replay->format, 255, 255, 255));
SDL_BlitSurface(replay, NULL, ecran, &positionreplay);

instruction = SDL_LoadBMP("3.bmp");
SDL_SetColorKey(instruction, SDL_SRCCOLORKEY, SDL_MapRGB(instruction->format, 255, 255, 255));
SDL_BlitSurface(instruction, NULL, ecran, &positioninstruction);

option = SDL_LoadBMP("4.bmp");
SDL_SetColorKey(option, SDL_SRCCOLORKEY, SDL_MapRGB(instruction->format, 255, 255, 255));
SDL_BlitSurface(option, NULL, ecran, &positionoption);

exit = SDL_LoadBMP("5.bmp");
SDL_SetColorKey(exit, SDL_SRCCOLORKEY, SDL_MapRGB(exit->format, 255, 255, 255));
SDL_BlitSurface(exit, NULL, ecran, &positionexit);

SDL_Flip(ecran);
break;
}

else if((event.motion.y>240 && event.motion.y<290) && (event.motion.x>540 && event.motion.x <770)) 
{
play = SDL_LoadBMP("1.bmp");
SDL_SetColorKey(play, SDL_SRCCOLORKEY, SDL_MapRGB(play->format, 255, 255, 255));
SDL_BlitSurface(play, NULL, ecran, &positionplay);

replay = SDL_LoadBMP("2.bmp");
SDL_SetColorKey(replay, SDL_SRCCOLORKEY, SDL_MapRGB(replay->format, 255, 255, 255));
SDL_BlitSurface(replay, NULL, ecran, &positionreplay);

instruction = SDL_LoadBMP("3a.bmp");
SDL_SetColorKey(instruction, SDL_SRCCOLORKEY, SDL_MapRGB(instruction->format, 255, 255, 255));
SDL_BlitSurface(instruction, NULL, ecran, &positioninstruction);

option = SDL_LoadBMP("4.bmp");
SDL_SetColorKey(option, SDL_SRCCOLORKEY, SDL_MapRGB(instruction->format, 255, 255, 255));
SDL_BlitSurface(option, NULL, ecran, &positionoption);

exit = SDL_LoadBMP("5.bmp");
SDL_SetColorKey(exit, SDL_SRCCOLORKEY, SDL_MapRGB(exit->format, 255, 255, 255));
SDL_BlitSurface(exit, NULL, ecran, &positionexit);

SDL_Flip(ecran);
break;
}


else if((event.motion.y>310 && event.motion.y<360) && (event.motion.x>540 && event.motion.x <770)) 
{
play = SDL_LoadBMP("1.bmp");
SDL_SetColorKey(play, SDL_SRCCOLORKEY, SDL_MapRGB(play->format, 255, 255, 255));
SDL_BlitSurface(play, NULL, ecran, &positionplay);

replay = SDL_LoadBMP("2.bmp");
SDL_SetColorKey(replay, SDL_SRCCOLORKEY, SDL_MapRGB(replay->format, 255, 255, 255));
SDL_BlitSurface(replay, NULL, ecran, &positionreplay);

instruction = SDL_LoadBMP("3.bmp");
SDL_SetColorKey(instruction, SDL_SRCCOLORKEY, SDL_MapRGB(instruction->format, 255, 255, 255));
SDL_BlitSurface(instruction, NULL, ecran, &positioninstruction);

option = SDL_LoadBMP("4a.bmp");
SDL_SetColorKey(option, SDL_SRCCOLORKEY, SDL_MapRGB(instruction->format, 255, 255, 255));
SDL_BlitSurface(option, NULL, ecran, &positionoption);

exit = SDL_LoadBMP("5.bmp");
SDL_SetColorKey(exit, SDL_SRCCOLORKEY, SDL_MapRGB(exit->format, 255, 255, 255));
SDL_BlitSurface(exit, NULL, ecran, &positionexit);

SDL_Flip(ecran);
break;
}

else if((event.motion.y>380 && event.motion.y<430) && (event.motion.x>540 && event.motion.x <770))
{
play = SDL_LoadBMP("1.bmp");
SDL_SetColorKey(play, SDL_SRCCOLORKEY, SDL_MapRGB(play->format, 255, 255, 255));
SDL_BlitSurface(play, NULL, ecran, &positionplay);

replay = SDL_LoadBMP("2.bmp");
SDL_SetColorKey(replay, SDL_SRCCOLORKEY, SDL_MapRGB(replay->format, 255, 255, 255));
SDL_BlitSurface(replay, NULL, ecran, &positionreplay);

instruction = SDL_LoadBMP("3.bmp");
SDL_SetColorKey(instruction, SDL_SRCCOLORKEY, SDL_MapRGB(instruction->format, 255, 255, 255));
SDL_BlitSurface(instruction, NULL, ecran, &positioninstruction);

option = SDL_LoadBMP("4.bmp");
SDL_SetColorKey(option, SDL_SRCCOLORKEY, SDL_MapRGB(instruction->format, 255, 255, 255));
SDL_BlitSurface(option, NULL, ecran, &positionoption);

exit = SDL_LoadBMP("5a.bmp");
SDL_SetColorKey(exit, SDL_SRCCOLORKEY, SDL_MapRGB(exit->format, 255, 255, 255));
SDL_BlitSurface(exit, NULL, ecran, &positionexit);
SDL_Flip(ecran);
break;
}
else
{
play = SDL_LoadBMP("1.bmp");
SDL_SetColorKey(play, SDL_SRCCOLORKEY, SDL_MapRGB(play->format, 255, 255, 255));
SDL_BlitSurface(play, NULL, ecran, &positionplay);

replay = SDL_LoadBMP("2.bmp");
SDL_SetColorKey(replay, SDL_SRCCOLORKEY, SDL_MapRGB(replay->format, 255, 255, 255));
SDL_BlitSurface(replay, NULL, ecran, &positionreplay);

instruction = SDL_LoadBMP("3.bmp");
SDL_SetColorKey(instruction, SDL_SRCCOLORKEY, SDL_MapRGB(instruction->format, 255, 255, 255));
SDL_BlitSurface(instruction, NULL, ecran, &positioninstruction);

option = SDL_LoadBMP("4.bmp");
SDL_SetColorKey(option, SDL_SRCCOLORKEY, SDL_MapRGB(option->format, 255, 255, 255));
SDL_BlitSurface(option, NULL, ecran, &positionoption);

exit = SDL_LoadBMP("5.bmp");
SDL_SetColorKey(exit, SDL_SRCCOLORKEY, SDL_MapRGB(exit->format, 255, 255, 255));
SDL_BlitSurface(exit, NULL, ecran, &positionexit);
SDL_Flip(ecran);
break;
}





 case SDL_KEYDOWN: 
                switch(event.key.keysym.sym) 
                { 
                    case SDLK_UP: // Flèche haut 
b--; 

                      break; 
               
                    case SDLK_DOWN: // Flèche bas 
                   
 b++; 
} 
break; 
}

if (b==1)
{
play = SDL_LoadBMP("1a.bmp");
SDL_SetColorKey(play, SDL_SRCCOLORKEY, SDL_MapRGB(play->format, 255, 255, 255));
SDL_BlitSurface(play, NULL, ecran, &positionplay);

replay = SDL_LoadBMP("2.bmp");
SDL_SetColorKey(replay, SDL_SRCCOLORKEY, SDL_MapRGB(replay->format, 255, 255, 255));
SDL_BlitSurface(replay, NULL, ecran, &positionreplay);

instruction = SDL_LoadBMP("3.bmp");
SDL_SetColorKey(instruction, SDL_SRCCOLORKEY, SDL_MapRGB(instruction->format, 255, 255, 255));
SDL_BlitSurface(instruction, NULL, ecran, &positioninstruction);

option = SDL_LoadBMP("4.bmp");
SDL_SetColorKey(option, SDL_SRCCOLORKEY, SDL_MapRGB(instruction->format, 255, 255, 255));
SDL_BlitSurface(option, NULL, ecran, &positionoption);

exit = SDL_LoadBMP("5.bmp");
SDL_SetColorKey(exit, SDL_SRCCOLORKEY, SDL_MapRGB(exit->format, 255, 255, 255));
SDL_BlitSurface(exit, NULL, ecran, &positionexit);
SDL_Flip(ecran);
}
if (b==2)
{play = SDL_LoadBMP("1.bmp");
SDL_SetColorKey(play, SDL_SRCCOLORKEY, SDL_MapRGB(play->format, 255, 255, 255));
SDL_BlitSurface(play, NULL, ecran, &positionplay);

replay = SDL_LoadBMP("2a.bmp");
SDL_SetColorKey(replay, SDL_SRCCOLORKEY, SDL_MapRGB(replay->format, 255, 255, 255));
SDL_BlitSurface(replay, NULL, ecran, &positionreplay);

instruction = SDL_LoadBMP("3.bmp");
SDL_SetColorKey(instruction, SDL_SRCCOLORKEY, SDL_MapRGB(instruction->format, 255, 255, 255));
SDL_BlitSurface(instruction, NULL, ecran, &positioninstruction);

option = SDL_LoadBMP("4.bmp");
SDL_SetColorKey(option, SDL_SRCCOLORKEY, SDL_MapRGB(instruction->format, 255, 255, 255));
SDL_BlitSurface(option, NULL, ecran, &positionoption);

exit = SDL_LoadBMP("5.bmp");
SDL_SetColorKey(exit, SDL_SRCCOLORKEY, SDL_MapRGB(exit->format, 255, 255, 255));
SDL_BlitSurface(exit, NULL, ecran, &positionexit);
SDL_Flip(ecran);
}
if (b==3)
{play = SDL_LoadBMP("1.bmp");
SDL_SetColorKey(play, SDL_SRCCOLORKEY, SDL_MapRGB(play->format, 255, 255, 255));
SDL_BlitSurface(play, NULL, ecran, &positionplay);

replay = SDL_LoadBMP("2.bmp");
SDL_SetColorKey(replay, SDL_SRCCOLORKEY, SDL_MapRGB(replay->format, 255, 255, 255));
SDL_BlitSurface(replay, NULL, ecran, &positionreplay);

instruction = SDL_LoadBMP("3a.bmp");
SDL_SetColorKey(instruction, SDL_SRCCOLORKEY, SDL_MapRGB(instruction->format, 255, 255, 255));
SDL_BlitSurface(instruction, NULL, ecran, &positioninstruction);

option = SDL_LoadBMP("4.bmp");
SDL_SetColorKey(option, SDL_SRCCOLORKEY, SDL_MapRGB(instruction->format, 255, 255, 255));
SDL_BlitSurface(option, NULL, ecran, &positionoption);

exit = SDL_LoadBMP("5.bmp");
SDL_SetColorKey(exit, SDL_SRCCOLORKEY, SDL_MapRGB(exit->format, 255, 255, 255));
SDL_BlitSurface(exit, NULL, ecran, &positionexit);
SDL_Flip(ecran);
}
if (b==4)
{play = SDL_LoadBMP("1.bmp");
SDL_SetColorKey(play, SDL_SRCCOLORKEY, SDL_MapRGB(play->format, 255, 255, 255));
SDL_BlitSurface(play, NULL, ecran, &positionplay);

replay = SDL_LoadBMP("2.bmp");
SDL_SetColorKey(replay, SDL_SRCCOLORKEY, SDL_MapRGB(replay->format, 255, 255, 255));
SDL_BlitSurface(replay, NULL, ecran, &positionreplay);

instruction = SDL_LoadBMP("3.bmp");
SDL_SetColorKey(instruction, SDL_SRCCOLORKEY, SDL_MapRGB(instruction->format, 255, 255, 255));
SDL_BlitSurface(instruction, NULL, ecran, &positioninstruction);

option = SDL_LoadBMP("4a.bmp");
SDL_SetColorKey(option, SDL_SRCCOLORKEY, SDL_MapRGB(instruction->format, 255, 255, 255));
SDL_BlitSurface(option, NULL, ecran, &positionoption);

exit = SDL_LoadBMP("5.bmp");
SDL_SetColorKey(exit, SDL_SRCCOLORKEY, SDL_MapRGB(exit->format, 255, 255, 255));
SDL_BlitSurface(exit, NULL, ecran, &positionexit);
SDL_Flip(ecran);
}
if(b==5)
{
play = SDL_LoadBMP("1.bmp");
SDL_SetColorKey(play, SDL_SRCCOLORKEY, SDL_MapRGB(play->format, 255, 255, 255));
SDL_BlitSurface(play, NULL, ecran, &positionplay);

replay = SDL_LoadBMP("2.bmp");
SDL_SetColorKey(replay, SDL_SRCCOLORKEY, SDL_MapRGB(replay->format, 255, 255, 255));
SDL_BlitSurface(replay, NULL, ecran, &positionreplay);

instruction = SDL_LoadBMP("3.bmp");
SDL_SetColorKey(instruction, SDL_SRCCOLORKEY, SDL_MapRGB(instruction->format, 255, 255, 255));
SDL_BlitSurface(instruction, NULL, ecran, &positioninstruction);

option = SDL_LoadBMP("4.bmp");
SDL_SetColorKey(option, SDL_SRCCOLORKEY, SDL_MapRGB(instruction->format, 255, 255, 255));
SDL_BlitSurface(option, NULL, ecran, &positionoption);

exit = SDL_LoadBMP("5a.bmp");
SDL_SetColorKey(exit, SDL_SRCCOLORKEY, SDL_MapRGB(exit->format, 255, 255, 255));
SDL_BlitSurface(exit, NULL, ecran, &positionexit);
SDL_Flip(ecran);
}



if(b>5) 
{b=0; 
}else if(b<0) 
{b=5;} 









/*case SDL_MOUSEBUTTONUP:

 switch (event.button.button) 
 { 
case SDL_BUTTON_LEFT:


if((event.button.y>0 && event.button.y<0) && (event.button.x>100 && event.button.x <800)) 
{
SDL_UpdateRect(ecran,0,0,0,0);
SDL_BlitSurface(ll, NULL, ecran, &positionll);
SDL_Flip(ecran);
break;
} 

else if((event.button.y>0 && event.button.y<0) && (event.button.x>100 && event.button.x <800)) 
{

SDL_UpdateRect(ecran,0,0,0,0);
SDL_BlitSurface(ll, NULL, ecran, &positionll);
SDL_Flip(ecran);
break;
}
else if((event.button.y>0 && event.button.y<0) && (event.button.x>100 && event.button.x <800)) 
{

SDL_UpdateRect(ecran,0,0,0,0);
SDL_BlitSurface(ll, NULL, ecran, &positionll);
SDL_Flip(ecran);
break;
}
else if((event.button.y>0 && event.button.y<0) && (event.button.x>100 && event.button.x <800)) 
{
SDL_UpdateRect(ecran,0,0,0,0);
SDL_BlitSurface(ll, NULL, ecran, &positionll);
SDL_Flip(ecran);
break;
}
else if((event.button.y>0 && event.button.y<0) && (event.button.x>100 && event.button.x <800)) 
{
SDL_UpdateRect(ecran,0,0,0,0);
SDL_BlitSurface(ll, NULL, ecran, &positionll);
SDL_Flip(ecran);
break;
}

}

*/


}

  

SDL_FreeSurface(imageDeFond); /* On libère la surface */
SDL_FreeSurface(play);
SDL_FreeSurface(replay);
SDL_FreeSurface(instruction);
SDL_FreeSurface(option);
SDL_FreeSurface(exit);
SDL_FreeSurface(ll);
SDL_Flip(ecran);
SDL_Quit();

return EXIT_SUCCESS;
}



